<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>您好Springboot</title>
</head>
<body>
	<table border="1px" width="65%" align="center">
		<tr>
			<td colspan="6" align="center"><h3>学生信息</h3></td>
		</tr>
		<tr>
			<th>编号</th>
			<th>姓名</th>
			<th>年龄</th>
			<th>性别</th>
			<th></th>
		</tr>
		<tbody id="tbodyId">

		</tbody>
	</table>
<script src="/js/jquery-3.4.1.min.js"></script>
<script type="text/javascript">
	$(function(){
		debugger
		let url ="/doAjaxFindAll";
		$.getJSON(url,function(result){
			doCreatedTable(result);
            // doCreatedTable2(result);
		})
	})

    //遍历数据的反方1
    function doCreatedTable2(result){

        for(let user of result){
            //console.log(user);
            let id = user.id;
            let name = user.name;
            let age = user.age;
            let sex = user.sex;
            let tr = "<tr align='center'><td>"+id+"</td><td>"+name+"</td><td>"+age+"</td><td>"+sex+"</td></tr>"
            $("#tbodyId").append(tr);
        }
    }

    //遍历数据的方式2
	function doCreatedTable(result){
		result.forEach(item=>{
		    let id= `id=\${item.id}`;
		    console.log(id)
            //模板字符串
			let tr=`
				<tr>
					<td>\${item.id}</td>
					<td>\${item.name}</tb>
					<td>\${item.age}</td>
					<td>\${item.sex}</td>
				</tr>`;
            //字符串拼接
           /* let tr=$("<tr></tr>")
            tr.append(
                "<td>"+item.id+"</td>"+
                "<td>"+item.name+"</td>"+
                "<td>"+item.age+"</td>"+
                "<td>"+item.sex+"</td>");*/
		$("#tbodyId").append(tr)
		})
	}
</script>
</body>
</html>